import sys
import cv2
import numpy as np
import matplotlib
matplotlib.use('TkAgg')  # 或尝试 'Qt5Agg'、'WXAgg'
import matplotlib.pyplot as plt
fig,ax=plt.subplots()


def get_bph(image_path:str)->list:
    lst_bph=[]
    img = cv2.imread(image_path)
    if img is None:
        raise ValueError("无法读取图像，请检查路径是否正确")

    h, w = img.shape[:2]
    for i in range(0,h):
        lst_bph.append(np.mean(img[i,:]))
    return lst_bph


def show_bph(image_path:str):
    lst_bph=get_bph(image_path)
    xaxis=list(range(1, len(lst_bph)+1,1))
    ax.plot(xaxis,lst_bph)

    fig.canvas.manager.set_window_title(f"白平衡灰度值输出")
    ax.set_xlabel("X axis", fontsize=12) 
    ax.set_ylabel("gray value", fontsize=12) 

    plt.legend(loc='upper right')
    plt.show()

if __name__=="__main__":
    show_bph(sys.argv[1])
    pass


